package com.mc.read.adminapi.service;

import com.alibaba.fastjson.JSON;
import com.mc.read.adminapi.Aspect.UserLog;
import com.mc.read.adminapi.manager.LoginManager;
import com.mc.read.common.emun.ServiceCodeEnum;
import com.mc.read.common.exception.ServiceException;
import com.mc.read.vo.request.BaseRequest;
import com.mc.read.vo.respose.BaseRespose;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liuhao
 * @date 2019/6/12 10:18
 */
@Service
@Slf4j
public class LoginService {
    @Autowired
    LoginManager loginManager;

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 员工登录 userLogin
     **/
    @UserLog(operateName = "登录", type = 0)
    public BaseRespose userLogin(BaseRequest baseRequest) {
        log.info("员工登录 开始,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = loginManager.userLogin(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("员工登录 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("员工登录 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }
}
